/* GUI CONVERTED from sosoisd.p (converter v1.76) Sun May 25 18:34:52 2003 */
/* sosoisd.p - SALES ORDER SHIPMENT SELECT LINE QUANITIES TO SHIP             */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.70 $                                                          */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 07/01/93   BY: JJS *GC96*    */
/*                                        (split from sosoism.p)  */
/* REVISION: 7.3      LAST MODIFIED: 07/02/93   BY: JJS *H019*    */
/* REVISION: 7.4      LAST MODIFIED: 08/13/93   BY: dpm *H069*    */
/* REVISION: 7.4      LAST MODIFIED: 08/23/93   BY: cdt *H049*    */
/* REVISION: 7.4      LAST MODIFIED: 01/21/94   BY: afs *FL52*    */
/* REVISION: 7.4      LAST MODIFIED: 02/07/94   BY: afs *FL83*    */
/* REVISION: 7.4      LAST MODIFIED: 03/08/94   BY: afs *FM79*    */
/* REVISION: 7.4      LAST MODIFIED: 04/21/94   BY: dpm *H360*    */
/* REVISION: 7.4      LAST MODIFIED: 06/16/94   BY: afs *FO97*    */
/* REVISION: 7.4      LAST MODIFIED: 07/15/94   BY: afs *FP43*    */
/* REVISION: 7.4      LAST MODIFIED: 08/29/94   BY: bcm *H494*    */
/* Oracle changes (share-locks)      09/13/94   BY: rwl *FR31*    */
/* REVISION: 7.4      LAST MODIFIED: 09/26/94   BY: ljm *GM78*    */
/* REVISION: 7.4      LAST MODIFIED: 10/05/94   BY: cdt *FS10*    */
/* REVISION: 8.5      LAST MODIFIED: 11/01/94   BY: pmf *GN31*    */
/* REVISION: 8.5      LAST MODIFIED: 11/20/94   BY: GWM *H604*    */
/* REVISION: 8.5      LAST MODIFIED: 10/05/94   by: mwd *J034*    */
/* REVISION: 8.5      LAST MODIFIED: 12/09/94   by: taf *J038*    */
/* REVISION: 8.5      LAST MODIFIED: 12/28/94   by: ktn *J041*    */
/* REVISION: 8.5      LAST MODIFIED: 01/07/95   by: smp *G0BM*    */
/* REVISION: 8.5      LAST MODIFIED: 03/06/95   BY: smp *F0LQ*    */
/* REVISION: 8.5      LAST MODIFIED: 05/17/95   by: sxb *J04D*    */
/*                                   08/03/95   BY: jym *G0T9*    */
/*                                   08/15/95   BY: vrn *G0V3*    */
/*                                   09/07/95   BY: jym *F0V3*    */
/*                                   09/12/95   BY: vrn *G0X3*    */
/*                                   11/30/95   BY: kjm *G1F7*    */
/*                                   11/07/95   BY: taf *J053*    */
/*                                   03/11/96   BY: wjk *J0DV*    */
/*                                   03/17/96   BY: kxn *J0FN*    */
/* REVISION: 8.5      LAST MODIFIED: 04/11/96   BY: rpw *J0HS*    */
/* REVISION: 8.5      LAST MODIFIED: 04/15/96   BY: *G1RS* Art Schain        */
/* REVISION: 7.5      LAST MODIFIED: 03/23/94   BY: *J04C* Greco Steenmetz   */
/* REVISION: 7.5      LAST MODIFIED: 06/06/94   BY: *J04C* Dennis Taylor     */
/* REVISION: 8.5      LAST MODIFIED: 04/14/95   BY: *J04C* Sue Poland        */
/* REVISION: 8.5      LAST MODIFIED: 12/03/95   BY: *J04C* Tom Vogten        */
/* REVISION: 8.5      LAST MODIFIED: 02/13/96   BY: *J04C* Markus Barone     */
/* REVISION: 8.5      LAST MODIFIED: 04/29/96   BY: *G1T4* Tony Patel        */
/* REVISION: 8.5      LAST MODIFIED: 05/14/96   BY: *G1LV* Vinay Nayak-Sujir */
/* REVISION: 8.5      LAST MODIFIED: 06/05/96   BY: *J0QV* Sue Poland        */
/* REVISION: 8.5      LAST MODIFIED: 06/13/96   BY: *G1Y6* Sue Poland        */
/* REVISION: 8.5      LAST MODIFIED: 07/09/96   BY: *J0NK* Kieu Nguyen       */
/* REVISION: 8.5      LAST MODIFIED: 07/11/96   BY: *J0VW* T. Farnsworth     */
/* REVISION: 8.5      LAST MODIFIED: 07/23/96   BY: *J10Q* Andy Wasilczuk    */
/* REVISION: 8.6      LAST MODIFIED: 09/24/96   BY: *K003* Forrest Mori      */
/* REVISION: 8.6      LAST MODIFIED: 01/03/97   BY: *J1CR* Sue Poland        */
/* REVISION: 8.6      LAST MODIFIED: 04/15/97   BY: *H0W3* Suresh Nayak      */
/* REVISION: 8.6      LAST MODIFIED: 05/06/97   BY: *G2MQ* Sue Poland        */
/* REVISION: 8.6      LAST MODIFIED: 07/03/97   BY: *H1B7* Aruna Patil       */
/* REVISION: 8.6      LAST MODIFIED: 09/26/97   BY: *J21P* Aruna Patil       */
/* REVISION: 8.6      LAST MODIFIED: 11/07/97   BY: *K15N* Jim Williams      */
/* REVISION: 8.6      LAST MODIFIED: 01/14/98   BY: *J29W* Aruna Patil       */
/* REVISION: 8.6      LAST MODIFIED: 02/11/98   BY: *H1JL* Seema Varma       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 02/26/98   BY: *J2FY* Jim Williams      */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton      */
/* REVISION: 8.6E     LAST MODIFIED: 06/30/98   BY: *J2PB* Dana Tunstall     */
/* REVISION: 8.6E     LAST MODIFIED: 08/03/98   BY: *L024* Sami Kureishy     */
/* REVISION: 9.0      LAST MODIFIED: 11/11/98   BY: *M00R* Sue Poland        */
/* REVISION: 9.0      LAST MODIFIED: 12/16/98   BY: *J371* Niranjan R.       */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 07/13/99   BY: *J2MD* A. Philips        */
/* REVISION: 9.1      LAST MODIFIED: 08/27/99   BY: *J3J9* Satish Chavan     */
/* REVISION: 9.1      LAST MODIFIED: 10/27/99   BY: *N03P* Mayse Lai         */
/* REVISION: 9.1      LAST MODIFIED: 10/28/99   BY: *K240* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 05/17/00   BY: *L0XV* Kedar Deherkar    */
/* REVISION: 9.1      LAST MODIFIED: 06/30/00   BY: *N0DX* Mudit Mehta       */
/* REVISION: 9.1      LAST MODIFIED: 07/10/00   BY: *M0PQ* Falguni Dalal     */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown        */
/* REVISION: 9.1      LAST MODIFIED: 12/14/00   BY: *M0XX* Ashwini G.        */
/* REVISION: 9.1      LAST MODIFIED: 01/11/01   BY: *M0XM* Rajesh Lokre      */
/* REVISION: 9.1      LAST MODIFIED: 10/14/00   BY: *N0WB* BalbeerS Rajput   */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.45        BY: Katie Hilbert      DATE: 04/01/01  ECO: *P002* */
/* Revision: 1.46        BY: Russ Witt          DATE: 04/20/01  ECO: *P00J* */
/* Revision: 1.47        BY: Rajesh Thomas      DATE: 07/23/01  ECO: *M136* */
/* Revision: 1.48        BY: Hareesh V          DATE: 10/07/01  ECO: *P027* */
/* Revision: 1.49        BY: Sandeep P.         DATE: 11/28/01  ECO: *N16L* */
/* Revision: 1.50        BY: Ed van de Gevel    DATE: 12/03/01  ECO: *N16R* */
/* Revision: 1.53        BY: Rajesh Kini        DATE: 01/28/02  ECO: *N18G* */
/* Revision: 1.54        BY: Nikita Joshi       DATE: 01/14/02  ECO: *M1MH* */
/* Revision: 1.56        BY: Manisha Sawant     DATE: 02/19/02  ECO: *N19P* */
/* Revision: 1.57        BY: Rajaneesh S.       DATE: 02/21/02  ECO: *L13N* */
/* Revision: 1.59        BY: Patrick Rowan      DATE: 04/24/02  ECO: *P00G* */
/* Revision: 1.60        BY: Jean Miller        DATE: 05/10/02  ECO: *P05V* */
/* Revision: 1.62        BY: Ashish Maheshwari  DATE: 07/17/02  ECO: *N1GJ* */
/* Revision: 1.63        BY: Ed van de Gevel    DATE: 09/05/02  ECO: *P0HQ* */
/* Revision: 1.67        BY: Rajiv Ramaiah      DATE: 01/13/03  ECO: *N23Z* */
/* Revision: 1.68        BY: Shilpa Athalye     DATE: 02/20/03  ECO: *P0MZ* */
/* Revision: 1.69        BY: Subashini Bala     DATE: 02/25/03  ECO: *N28C* */
/* $Revision: 1.70 $       BY: Narathip W.        DATE: 05/21/03  ECO: *P0S8* */
/* Revision: eb2 sp3 $       BY: Joy Huang          DATE: 10/26/03  ECO: *HK-S-029* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/******************************************************************************/
/* Due to the introduction of the module Project Realization Management (PRM) */
/* the term Material Order (MO) replaces all previous references to Service   */
/* Engineer Order (SEO) in the user interface. Material Order is a type of    */
/* Sales Order used by an engineer to obtain inventory needed for service     */
/* work. In PRM, a material order is used to obtain inventory for project     */
/* work.                                                                      */
/******************************************************************************/

/******************************************************************/
/*                                                                */
/*    Any for-each loops which go through every sod_det for a     */
/*    so_nbr (i.e. for each sod_det where sod_nbr = so_nbr )      */
/*    should have the following statments first in the loop.      */
/*                                                                */
/*       if (sorec = fsrmarec    and sod_fsm_type  <> "RMA-RCT")  */
/*       or (sorec = fsrmaship   and sod_fsm_type  <> "RMA-ISS")  */
/*       or (sorec = fssormaship and sod_fsm_type  =  "RMA-RCT")  */
/*       or (sorec = fssoship    and sod_fsm_type  <> "")         */
/*       then next.                                               */
/*                                                                */
/*    this is to prevent rma receipt line from being processed    */
/*    when issue lines are processed (sas).                       */
/*                                                                */
/******************************************************************/

{mfdeclre.i}
{cxcustom.i "SOSOISD.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* CONSIGNMENT TEMP TABLE DEFINITION */
{socnis.i}

define input-output parameter table for tt_consign_shipment_detail.

define new shared variable sod_recno as recid.
define new shared variable so_recno as recid.
define new shared variable picking_logic  as logical label "Use Pick Logic".

/* DEFINE SHARED VARIABLE RNDMTHD FOR GPFRLWT.P */
define shared variable rndmthd like rnd_rnd_mthd.
define shared variable issue_or_receipt as character.
define shared variable total_lotserial_qty like sod_qty_chg.
define shared variable multi_entry like mfc_logical label "Multi Entry".
define shared variable site like sr_site no-undo.
define shared variable location like sr_loc no-undo.
define shared variable loc like pt_loc.
define shared variable lotserial like sr_lotser no-undo.
define shared variable lotserial_qty like sr_qty no-undo.
define shared variable trans_um like pt_um.
define shared variable trans_conv like sod_um_conv.
define shared variable transtype as character initial "ISS-SO".
define shared variable change_db like mfc_logical.
define shared variable ship_site like sod_site.
define shared variable ship_db like dc_name.
define shared variable ship_so like so_nbr.
define shared variable ship_line like sod_line.
define shared variable lotref like sr_ref format "x(8)" no-undo.
define shared variable lotserial_control as character.
define shared variable eff_date like glt_effdate label "Effective".
define shared variable undo-all like mfc_logical no-undo.
define shared variable so_mstr_recid as recid.
define shared variable so_db like dc_name.
define shared variable cline as character.
define shared variable undo-select like mfc_logical no-undo.
define shared variable freight_ok like mfc_logical.
define shared variable calc_fr like mfc_logical.
define shared variable disp_fr like mfc_logical.
define shared variable exch_rate like exr_rate.
define shared variable exch_rate2 like exr_rate2.
define shared variable exch_ratetype like exr_ratetype.
define shared variable exch_exru_seq like exru_seq.

define variable line          like sod_line format ">>>" no-undo.
define variable yn            like mfc_logical no-undo.
define variable i             as integer no-undo.
define variable cancel_bo     like mfc_logical label "Cancel B/O" no-undo.
define variable mod_iss       like mfc_logical label "Issue Components" no-undo.
define variable err-flag        as integer no-undo.
define variable msgnbr          as integer no-undo.
define variable sav_global_type like cmt_type no-undo.
define variable detqty          like sod_qty_ord no-undo.
define variable original_db     like ship_db no-undo.
define variable new_db          like ship_db no-undo.
define variable lotnext         like wo_lot_next no-undo.
define variable lotprcpt        like wo_lot_rcpt no-undo.
define variable linked-line     like sod_line no-undo.
define variable done_entry      like mfc_logical no-undo.
define variable overissue_ok    like mfc_logical no-undo.
define variable lineid_list     as character no-undo.
define variable fr_title        as character no-undo.
define variable fac_bflush_comp as logical label "Automatic Backflush" no-undo.
define variable line_to_preissue   as logical no-undo.
define variable l_disc_pct1        as decimal no-undo.
define variable l_net_price        as decimal no-undo.
define variable l_list_price       as decimal no-undo.
define variable l_rec_no           as recid   no-undo.
define variable prev_lotserial_qty like sod_qty_chg no-undo.
define variable connect_db         like dc_name no-undo.
define variable db_undo            like mfc_logical no-undo.
define variable l_overship         as logical no-undo.
define variable l_remove_srwkfl    like mfc_logical no-undo.
define variable mc-error-number    like msg_nbr no-undo.
define variable disp_ord           as decimal no-undo.
define variable disp_ship          as decimal no-undo.
define variable ret-flag           as integer no-undo.
define variable l_sonbr            like sod_nbr no-undo.
define variable l_ship_one_line    like mfc_logical no-undo.
define variable l_sod_bo_chg       like sod_bo_chg  no-undo.

define buffer soddet for sod_det.

define temp-table tt_bo no-undo
   field tt_sod_line  like sod_line
   field tt_cancel_bo like mfc_logical
   index ttline is primary
      tt_sod_line.

for each tt_bo exclusive-lock:
   delete tt_bo.
end. /* FOR EACH tt_cancel_bo */

assign issue_or_receipt = getTermLabel("ISSUE",8).
{sosois1.i}

/* DEFINE VARIABLES USED IN GPGLEF1.P (GL CALENDAR VALIDATION) */
{gpglefv.i}

/* CONSIGNMENT VARIABLES. */
{socnvars.i}

for first mfc_ctrl
   fields(mfc_field mfc_logical)
   where mfc_field = "fac_bflush_comp"
no-lock: end.

if available mfc_ctrl then
   fac_bflush_comp = mfc_logical.
else
   fac_bflush_comp = false.

l_ship_one_line = no.

/* FINDING mfc_ctrl RECORD IN WAREHOUSE CONTROL FILE */
for first mfc_ctrl
   fields(mfc_field mfc_logical)
   where mfc_field = "wi_ship_oneline"
no-lock:
   l_ship_one_line = mfc_logical.
end. /* FOR FIRST mfc_ctrl */

picking_logic = true.

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
fac_bflush_comp    colon 40 skip
   picking_logic      colon 40
 SKIP(.4)  /*GUI*/
with frame ship_comps width 80 side-labels
 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-ship_comps-title AS CHARACTER.
 F-ship_comps-title = (getFrameTitle("CONFIRM_CONFIGURED_ITEM_BACKFLUSH",60)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame ship_comps = F-ship_comps-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame ship_comps =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame ship_comps + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame ship_comps =
  FRAME ship_comps:HEIGHT-PIXELS - RECT-FRAME:Y in frame ship_comps - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME ship_comps = FRAME ship_comps:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame ship_comps:handle).

/* CHECK TO SEE IF CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
   "(input ENABLE_CUSTOMER_CONSIGNMENT,
     input 10,
     input ADG,
     input CUST_CONSIGN_CTRL_TABLE,
     output using_cust_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


for first so_mstr
   fields(so_bill so_curr so_cust so_ex_rate so_ex_rate2
          so_fr_list so_fr_min_wt so_fr_terms so_fsm_type
          so_nbr so_ship so_taxc)
   where recid(so_mstr) = so_mstr_recid
no-lock: end.

{&SOSOISD-P-TAG1}

/* SET FRAME TITLE TO CLEARLY INDICATE WHAT'S BEING SHIPPED */
if sorec = fsseoship then
   fr_title = getFrameTitle("MATERIAL_ORDER_LINE_ITEMS",35).
else if sorec = fsktship then
   fr_title = getFrameTitle("KIT_ASSEMBLY_LINE_ITEMS",35).
else
   fr_title = getFrameTitle("SALES_ORDER_LINE_ITEMS",35).

if change_db then do:
   {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

   assign
      connect_db = ship_db
      db_undo = no.
   run check-db-connect
      (input connect_db, input-output db_undo).
   if db_undo then undo, return.

   /* RETRIEVE BACKFLUSH FLAG FROM REMOTE DB IF NECESSARY */
   {gprun.i ""sobflush.p"" "(output fac_bflush_comp)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.


   assign
      connect_db = so_db
      db_undo = no.

   run check-db-connect
      (input connect_db, input-output db_undo).

   if db_undo then undo, return.

end.

line_to_preissue = false.

if (can-find (first sob_det
              where sob_nbr  = so_nbr
              and   sob_site = ship_site)
or  ship_site = "")
then do:

   for each sod_det
      fields(sod_bo_chg sod_cfg_type sod_confirm
             sod_cum_qty sod_desc sod_enduser
             sod_fa_nbr sod_fr_chg sod_fr_class
             sod_fr_list sod_fr_wt sod_fr_wt_um
             sod_fsm_type sod_line sod_list_pr
             sod_loc sod_lot sod_nbr sod_part
             sod_price sod_pr_list sod_qty_all
             sod_qty_chg sod_qty_ord sod_qty_pick
             sod_qty_ship sod_ref sod_rma_type
             sod_sched sod_sch_data sod_serial
             sod_site sod_std_cost sod_taxable
             sod_tax_env sod_tax_in sod_tax_usage
             sod_type sod_um sod_um_conv sod_upd_isb)
      where sod_nbr = so_nbr
   no-lock:

      if   sod_fa_nbr = ""
      and  sod_cfg_type <> "1" /* Not "1" Assemble-to-Order */
      and (can-find (first sob_det
                     where sob_nbr  = so_nbr
                     and   sob_line = sod_line
                     and   sob_site = ship_site) or
           ship_site = "")
      then do:
         /* There is at least one line we can do an automatic     */
         /* Backflush for.  That's all we wanted to know.         */
         line_to_preissue = true.
         leave.
      end.

   end.    /* for each sod_det */

end.   /* if can-find (first sob_det...) */

{&SOSOISD-P-TAG9}
if fac_bflush_comp and line_to_preissue then
   update
      fac_bflush_comp
      picking_logic
   with frame ship_comps.

hide frame ship_comps no-pause.
{&SOSOISD-P-TAG10}
/* LINE ITEM DISPLAY FORM */
{&SOSOISD-P-TAG13}
FORM /*GUI*/ 
with frame b title color normal fr_title
(if sorec = fsseoship or sorec = fsktship then 5 else 6) down width 80 THREE-D /*GUI*/.

{&SOSOISD-P-TAG14}

/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

/* RMA LINE ITEM DISPLAY FORM */
{&SOSOISD-P-TAG15}
FORM /*GUI*/ 
   sod_line
   sod_part
   sod_type
   disp_ord    format "->>>>>>9.9<<<<<<" label "Expected"
   sod_qty_chg format "->>>>>>9.9<<<<<<" label "To Receive"
   disp_ship   format "->>>>>>9.9<<<<<<" label "Received"
   sod_site
with frame f title color normal (getFrameTitle("RETURNED_LINE_ITEMS",28))
6 down width 80 THREE-D /*GUI*/.

{&SOSOISD-P-TAG16}

/* SET EXTERNAL LABELS */
setFrameLabels(frame f:handle).

sod_qty_chg:label in frame f = getTermLabel("TO_RECEIVE",10).

/* LINE ITEM ENTRY FORM */
FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
line           colon 13
   cancel_bo
   site           colon 53
   location       colon 67  label "Loc"
   lotserial_qty  colon 13
   lotserial      colon 53
   sod_part       colon 13
   sod_um
   lotref         colon 53
   sod_desc       colon 13
   multi_entry    colon 53
 SKIP(.4)  /*GUI*/
with frame c side-labels attr-space width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-c-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
 RECT-FRAME-LABEL:HIDDEN in frame c = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame c =
  FRAME c:HEIGHT-PIXELS - RECT-FRAME:Y in frame c - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME c = FRAME c:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

assign
   lotnext = ""
   lotprcpt = no
   line = 1.

loop0:
repeat transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


   if fac_bflush_comp and line_to_preissue
   then do:
      if change_db then do:
         {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         assign
            connect_db = ship_db
            db_undo = no.
         run check-db-connect
            (input connect_db, input-output db_undo).
         if db_undo then do:
            hide frame b.
            hide frame f.
            hide frame c.
            undo loop0, leave loop0.
         end.
      end.
      else
         so_recno = recid(so_mstr).

      {gprun.i ""soise05.p"" "(so_nbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if change_db then do:
         {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         assign
            connect_db = so_db
            db_undo = no.
         run check-db-connect
            (input connect_db, input-output db_undo).
         if db_undo then do:
            hide frame b.
            hide frame f.
            hide frame c.
            undo loop0, leave loop0.
         end.
      end.
   end.

   /* DISPLAY DETAIL */
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


      clear frame b all no-pause.
      clear frame c no-pause.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
      clear frame f all no-pause.

      if sorec = fsrmarec then
         view frame f.
      else
         view frame b.

      view frame c.

      if not can-find(first sod_det where sod_nbr = so_nbr) then do:
         {pxmsg.i &MSGNUM=611 &ERRORLEVEL=2}  /* Order has no line items */
         if batchrun
         then
            undo loop0, leave loop0.
         else
            leave.
      end.

      /* Display order detail */
      /* CODE ADDED TO FACILITATE ONE LINE SHIPMENT DURING CIM PROCESS */
      if execname = "sosois.p"
         and batchrun
         and l_ship_one_line
      then do:
         for first sod_det
            fields(sod_bo_chg sod_cfg_type sod_confirm sod_cum_qty
                   sod_desc sod_enduser sod_fa_nbr sod_fr_chg
                   sod_fr_class sod_fr_list sod_fr_wt sod_fr_wt_um
                   sod_fsm_type sod_line sod_list_pr sod_loc sod_lot
                   sod_nbr sod_part sod_price sod_pr_list sod_qty_all
                   sod_qty_chg sod_qty_ord sod_qty_pick sod_qty_ship
                   sod_ref sod_rma_type sod_sched sod_sch_data sod_serial
                   sod_site sod_std_cost sod_taxable sod_tax_env sod_tax_in
                   sod_tax_usage sod_type sod_um sod_um_conv sod_upd_isb)
            where sod_nbr  = so_nbr
              and sod_line = line
              and (sod_site = ship_site or ship_site = "")
         no-lock: end.
      end. /* IF execname = "sosois.p" ... */

      else do:

         for each sod_det no-lock
            where sod_nbr = so_nbr
              and sod_line >= line
              and (sod_site = ship_site or ship_site = "")
         by sod_line:

            /* Consider skipping this record based on something */
            if (sorec = fsrmarec and sod_rma_type  <> "I")
            or (sorec = fsrmaship and sod_rma_type  <> "O")
            or (sorec = fssormaship and sod_rma_type  =  "I")
            or (sorec = fssoship    and sod_fsm_type  <> "")
            then next.

            /* Use different display if receiving against an RMA */
            if  sorec = fsrmarec then do:

               assign
                  disp_ord  = sod_qty_ord * -1.0
                  disp_ship = sod_qty_ship * -1.0.

               display
                  sod_line
                  sod_part
                  sod_type
                  disp_ord     format "->>>>>>9.9<<<<<<" label "Expected"
                  sod_qty_chg  format "->>>>>>9.9<<<<<<" label "To Receive"
                  disp_ship    format "->>>>>>9.9<<<<<<" label "Received"
                  sod_site
               with frame f.

               if frame-line(f) = frame-down(f) then leave.
               down 1 with frame f.

            end. /* if fsrmarec */

            else do:

               for first tt_bo where tt_bo.tt_sod_line = sod_line
               no-lock: end.

               if not available tt_bo
               then do:
                  create tt_bo.
                  assign
                     tt_bo.tt_sod_line  = sod_line
                     tt_bo.tt_cancel_bo = cancel_bo.
               end. /* IF NOT AVAILABLE tt_bo */

               /* THE BACKORDER QUANTITY SHOULD BE DISPLAYED AS ZERO */
               /* FOR OVERISSUES WHEN CANCEL B/O IS YES              */
               if  tt_bo.tt_cancel_bo and sod_bo_chg < 0
               then
                  l_sod_bo_chg = 0.
               else
                  l_sod_bo_chg = sod_bo_chg.

               display
                  sod_line
                  sod_part
                  sod_type
                  sod_qty_all   format "->>>>>>9.9<<<<<<" label "Allocated"
                  sod_qty_pick  format "->>>>>>9.9<<<<<<" label "Picked"
                  sod_qty_chg   format "->>>>>>9.9<<<<<<" label "To Ship"
                  l_sod_bo_chg  format "->>>>>>9.9<<<<<<" label "Backorder"
                  sod_site
               with frame b.

               if frame-line(b) = frame-down(b) then leave.
               down 1 with frame b.

            end. /* if not fsrmarec */

         end.  /* Display order detail */

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* ELSE DO */

      line = 0.

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         /* gpiswrap.i QUERIES THE SESSION PARAMETER FOR */
         /* THE MFGWRAPPER TAG                           */
         if not {gpiswrap.i}
         then
            input clear.

         cancel_bo = no.
         update line cancel_bo with frame c width 80
         editing:

            /* TO SHOW SO LINES FOR SELECTED SO IN CHAR AND GUI */
            /* USING LOOK-UP OR DRILL DOWN BROWSE ON LINE FIELD.  */
            {gpbrparm.i &browse=gpbr241.p &parm=c-brparm1 &val="so_nbr"}
            {gpbrparm.i &browse=gplu241.p &parm=c-brparm1 &val="so_nbr"}

            l_sonbr = so_nbr.

            on leave of line in frame c do:
                    
               do on error undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.

                  {gpbrparm.i &browse=gpbr241.p &parm=c-brparm1 &val="l_sonbr"}
                  {gpbrparm.i &browse=gplu241.p &parm=c-brparm1 &val="l_sonbr"}
                  run q-leave in global-drop-down-utilities.
               end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* DO ON ERROR ... */

               run q-set-window-recid in global-drop-down-utilities.
               if return-value = "error"
                  then return no-apply.    
            end. /* ON LEAVE ... */

            if frame-field = "line" then do:

               {mfnp01.i sod_det line sod_line sod_nbr so_nbr
                  sod_nbrln}

               if recno <> ? then do:

                  line = sod_line.

                  for first pt_mstr
                     fields(pt_desc1 pt_lot_ser pt_part pt_price)
                     where pt_part = sod_part
                  no-lock: end.

                  display
                     line
                     sod_part
                     sod_desc
                     sod_um
                  with frame c.

                  if available pt_mstr then
                     display pt_desc1 @ sod_desc with frame c.
               end.

            end.

            else do:
               status input.
               readkey.
               apply lastkey.
            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.

         status input.

         if line = 0 then leave.

         find sod_det where sod_nbr = so_nbr and sod_line = line
         exclusive-lock no-error.

         {&SOSOISD-P-TAG7}

         if not available sod_det then do:
            /* Line item does not exist */
            {pxmsg.i &MSGNUM=45 &ERRORLEVEL=3}
            if batchrun then
               undo loop0, leave loop0.
            else
               undo, retry.
         end.
         if not sod_confirm then do:
            /* Sales order line has not been confirmed */
            {pxmsg.i &MSGNUM=646 &ERRORLEVEL=3}
            if batchrun then
               undo loop0, leave loop0.
            else
               undo, retry.
         end.

         /* Check if line has been staged */
         if not sod_sched and sod_sch_data <> "" then do:
            /* Ship line has been staged */
            {pxmsg.i &MSGNUM=8263 &ERRORLEVEL=3}
            if batchrun then
               undo loop0, leave loop0.
            else
               undo, retry.
         end.

         msgnbr = 0.
         if  sorec = fsrmarec and sod_rma_type <> "I"
         then
            msgnbr = 7228.  /* cannot process issues */

         if (sorec = fsrmaship     or
             sorec = fssoship      or
             sorec = fssormaship) and
             sod_rma_type = "I"
         then
            msgnbr = 7227.  /* cannot process returns */

         if  msgnbr <> 0 then do:
            {pxmsg.i &MSGNUM=msgnbr &ERRORLEVEL=3}
            if batchrun
            then
               undo loop0, leave loop0.
            else
               undo, retry.
         end.

         if ship_site <> "" and sod_site  <> ship_site
         then do:
            /* SITE OF THE LINE DOES NOT MATCH ... */
            {pxmsg.i &MSGNUM=4573 &ERRORLEVEL=3}
            if batchrun then
               undo loop0, leave loop0.
            else
               undo, retry.
         end. /* IF ship_site <> "" */

         {&SOSOISD-P-TAG8}
         display line sod_part sod_desc sod_um with frame c.

         for first pt_mstr
            fields(pt_desc1 pt_lot_ser pt_part pt_price)
            where pt_part = sod_part
         no-lock: end.

/*HK-S-029*/
                for first in_mstr
                   fields (in_site in_loc in_part)
                   where in_site = sod_site and in_part = sod_part
                   no-lock: end.
/*HK-S-029*/

         if available pt_mstr then
            display pt_desc1 @ sod_desc with frame c.

         lotserial_control = "".

         /* Don't bother with Item Master for Memo items */
         if sod_type = "" then do:
            if not available pt_mstr then do:
               /* WARNING - ITEM NOT IN INVENTORY */
               {pxmsg.i &MSGNUM=16 &ERRORLEVEL=2}
            end.
         end.
         {&SOSOISD-P-TAG2}
      end.

      if available pt_mstr then
         lotserial_control = pt_lot_ser.
      else
         lotserial_control = "".

      assign
         site                = ""
         location            = ""
         lotserial           = ""
         lotref              = ""
         lotserial_qty       = sod_qty_chg
         prev_lotserial_qty  = sod_qty_chg
         cline               = string(line)
         global_part         = sod_part
         trans_um            = sod_um
         trans_conv          = sod_um_conv
         multi_entry         = no
         sod_qty_chg         = 0
         total_lotserial_qty = 0 .

      /* Fill lotserial data for MO-line */
      if sod_fsm_type = "SEO" then
      assign
         lotserial     = sod_serial
         site          = sod_site
/*HK-S-029         location      = sod_loc.*/
/*HK-S-029*/       location      = in_loc.

      /* Total previously entered ship qtys for this line */
      {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.


      assign
         connect_db = ship_db
         db_undo = no.

      run check-db-connect
         (input connect_db, input-output db_undo).

      if db_undo then do:
         hide frame b.
         hide frame f.
         hide frame c.
         undo loop0, leave loop0.
      end.

      {gprun.i ""sosoiss5.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

      {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.


      assign
         connect_db = so_db
         db_undo = no.

      run check-db-connect
         (input connect_db, input-output db_undo).

      if db_undo then do:
         hide frame b.
         hide frame f.
         hide frame c.
         undo loop0, leave loop0.
      end.

      /* Default to SO site if no shipments exist */
      if site = "" then
      assign
         site     = sod_site
/*HK-S-029         location = sod_loc .*/
/*HK-S-029*/       location = in_loc .

      /* RMA receipt's for serialized item's are typically */
      /* for a single item. Therefore default the serial   */
      /* number, ref, and quantity for this item.          */
      if sod_serial    <> ""       and
         sod_fsm_type  = "RMA-RCT" and
         sod_rma_type  = "I"       and
         sod_qty_ord   = -1
      then
      assign
         lotserial = sod_serial
         lotserial_qty = sod_qty_ord * -1.

      {gprun.i ""gpsiver.p"" "(input site,
                               input ?,
                               output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         /* USER DOES NOT HAVE ACCESS TO THIS SITE */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         undo, retry.
      end.

      /* UPDATE INVENTORY LOCATION INFORMATION */
      setlot:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         /* FOR MO'S WITH KITS TO SHIP, WE DO NOT (!!!) WANT   */
         /* THE USER TO GO INTO MULTI-ENTRY MODE.  HE MUST BE  */
         /* DEALING WITH A QUANTITY OF 1, AND, IF HE HAPPENS   */
         /* TO HAVE PICKED AN INCOMPLETE KIT, WE'VE GOT AN     */
         /* EXTRA SR_WKFL HANGING AROUND (WITH SR_REV =        */
         /* SEO-DEL) TO SUPPORT THE BACKORDER REPORT THAT      */
         /* PRINTS AUTOMATICALLY FOLLOWING MO SHIPMENT TIME.   */
         if (sod_fsm_type = "SEO" and sod_type = "K") then
            multi_entry = no.

         display
            site
            location
            lotserial
            multi_entry
         with frame c.

         if change_db then do:
            {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               connect_db = ship_db
               db_undo = no.
            run check-db-connect
               (input connect_db, input-output db_undo).
            if db_undo then do:
               hide frame b.
               hide frame f.
               hide frame c.
               undo loop0, leave loop0.
            end.
         end.

         {gprun.i ""sosoiss6.p"" "(sod_nbr, sod_line)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if change_db then do:
            {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               connect_db = so_db
               db_undo = no.
            run check-db-connect
               (input connect_db, input-output db_undo).
            if db_undo then do:
               hide frame b.
               hide frame f.
               hide frame c.
               undo loop0, leave loop0.
            end.
         end.

         for first tt_bo
            where tt_bo.tt_sod_line = sod_line
         no-lock: end.
/*GUI*/ if global-beam-me-up then undo, leave.


         if available tt_bo then
            tt_bo.tt_cancel_bo = cancel_bo.

         /* SIMILARLY, FOR KITS/MO'S, DO NOT LET THE USER      */
         /* UPDATE THE MULTI-ENTRY FIELD.                      */
         {&SOSOISD-P-TAG3}
         update
            lotserial_qty
            site      when (sod_fsm_type <> "SEO" or sod_type <> "K")
            location  when (sod_fsm_type <> "SEO" or sod_type <> "K")
            lotserial when (sod_fsm_type <> "SEO" or sod_type <> "K")
            lotref    when (sod_fsm_type <> "SEO" or sod_type <> "K")
            multi_entry when (sod_type = "" and not multi_entry)
         with frame c
         editing:
            {&SOSOISD-P-TAG4}
            assign
               global_site = input site
               global_loc  = input location
               global_lot  = input lotserial.
            readkey.
            apply lastkey.
         end.

         /* CHECK FOR VALID SITE */
         if not can-find(si_mstr where si_site = site) then do:
            {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}  /* SITE DOES NOT EXIST */
            next-prompt site with frame c.
            undo setlot, retry.
         end.

         /* CHECK SITE FOR USER GROUP AUTHORIZATION */
         {gprun.i ""gpsiver.p"" "(input (input site),
                                  input ?,
                                  output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            /* USER DOES NOT HAVE ACCESS TO SITE */
            undo setlot, retry.
         end.

         /* If ship site doesn't match original site, make sure   */
         /* Database isn't changing at the same time (this change */
         /* Should be made in SO Maintenance so we don't have to  */
         /* Include the code here to copy the line into the       */
         /* Remote database).                                     */
         if global_db <> "" and site <> sod_site then do:

            if sod_site <> ship_site then do:
               for first si_mstr
                  fields(si_db si_entity si_site)
                  where si_site = sod_site
               no-lock: end.
               original_db = si_db.
            end.
            else
               original_db = ship_db.

            if site <> ship_site then do:
               for first si_mstr
                  fields(si_db si_entity si_site)
                  where si_site = site
               no-lock: end.
               new_db = si_db.
            end.
            else
               new_db = ship_db.

            if new_db <> original_db then do:
               /* SO line is for database # */
               {pxmsg.i &MSGNUM=2515 &ERRORLEVEL=3 &MSGARG1=original_db}
               next-prompt site with frame c.
               undo setlot, retry.
            end.

         end.

         /* If specified site is not defined ship-from site, */
         /* Make sure it's in the same database              */
         if global_db <> "" and site <> ship_site then do:

            for first si_mstr
               fields(si_db si_entity si_site)
               where si_site = site
            no-lock: end.

            if si_db <> ship_db then do:
               {pxmsg.i &MSGNUM=2512 &ERRORLEVEL=3}
               /* All ship-from sites must be in same db */
               next-prompt site with frame c.
               undo, retry.
            end.

         end.

         /* CHECK TO SEE IF RESERVED LOCATION EXISTS */
         /* FOR OTHER CUSTOMERS--                    */
         run check-reserved-location.

         if ret-flag = 0 then do:
            {pxmsg.i &MSGNUM=3346 &ERRORLEVEL=3}
            /* THIS LOCATION RESERVED FOR ANOTHER CUSTOMER */
            next-prompt location with frame c.
            undo setlot, retry.
         end.

         /* VALIDATE OPEN GL PERIOD FOR ENTITY AND DATABASE */
         /* SPECIFIED ON THE SHIPMENT LINE. WE NEED TO DO   */
         /* DO THIS HERE BECAUSE THE SITE AND ENTITY CAN BE */
         /* DIFFERENT THAN WHAT WAS ENTERED IN FIRST FRAME. */

         /* VALIDATE GL PERIOD FOR SPECIFIED ENTITY/DATABASE */

         for first si_mstr
            fields(si_db si_entity si_site)
            where si_site = site
         no-lock: end.

         {gpglef3.i &from_db = so_db
            &to_db   = ship_db
            &module  = ""IC""
            &entity  = si_entity
            &date    = eff_date
            &prompt  = "site"
            &frame   = "c"
            &loop    = "setlot"}

         /* GET TAX MANAGEMENT DATA ONLY IF */
         /* THE SITE HAS BEEN CHANGED       */
         if site <> sod_site and sod_taxable then do:
            undo-all = true.
            {gprun.i ""sosoistx.p""
               "(input so_mstr_recid,
                 input site,
                 input sod_site,
                 input sod_fsm_type,
                 input-output sod_taxable,
                 input-output so_taxc,
                 input-output sod_tax_usage,
                 input-output sod_tax_env,
                 input-output sod_tax_in,
                 input-output undo-all)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if undo-all then undo setlot, retry.
         end.

         /*  IF THIS IS SOME TYPE OF RETURN THAT WOULD LIKE TO UPDATE
             THE INSTALLED BASE, BUT THE PART/SERIAL/REF DOESN'T
             EXIST IN THE ISB, OR THE QUANTITY DOESN'T MATCH THE
             ISB QUANTITY, WARN THE USER */

         if not available soc_ctrl then do:
            for first soc_ctrl
                  fields(soc_pl_req soc_returns_isb) no-lock:
            end. /* FOR FIRST SOC_CTRL */
         end.

         if multi_entry  = no    and
            (sod_rma_type = "I" or soc_returns_isb) and
            sod_qty_ord < 0 and
            sod_upd_isb  = yes
         then do:

            for first isb_mstr
               fields(isb_eu_nbr isb_part isb_qty
                      isb_ref isb_serial)
               where isb_eu_nbr = sod_enduser
               and isb_part = sod_part
               and isb_serial = lotserial
               and isb_ref = integer(lotref)
            no-lock: end.

            if  not available isb_mstr then do:
               {pxmsg.i &MSGNUM=7123 &ERRORLEVEL=2}
               /* ITEM DOES NOT EXIST IN INSTALLED BASE */
            end.

            else do:
               /* LOT_SERIAL_QTY NOTES:  IF YOU'RE DOING AN
                  RMA RETURN, LOTSERIAL_QTY IS POSITIVE.
                  BUT, IF YOU'RE DOING A S.O. RETURN,
                  THIS QTY IS NEGATIVE.

                  WE NEED TO WARN THE USER IF THE QTY BEING
                  RETURNED IS OTHER THAN THE QTY IN THE ISB.
                  WITH THE CONDITIONS NOTED ABOVE, THIS TAKES
                  A SPECIAL CHECK, DEPENDING ON THE TYPE OF
                  RETURN BEING DONE - AN RMA OR S.O. */

               if (sorec = fsrmarec and isb_qty <> lotserial_qty)
               or (sorec = fssoship and - (isb_qty) <> lotserial_qty)
               then do:
                  /* INSTALLED BASE QTY (#) DOESN'T MATCH ITEM QTY */
                  {pxmsg.i &MSGNUM=1275 &ERRORLEVEL=2
                           &MSGARG1=trim(string(isb_qty,"">,>>>,>>>,>>9.9<<""))}
               end.    /* if sorec = fsrmarec... */

            end.    /* else, available isb_mstr, do */

         end. /* if multi_entry = no and ... */

         if change_db then do:
            {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               connect_db = ship_db
               db_undo = no.
            run check-db-connect
               (input connect_db, input-output db_undo).
            if db_undo then do:
               hide frame b.
               hide frame f.
               hide frame c.
               undo loop0, leave loop0.
            end.
         end.

         assign
            ship_line = line
            sod_recno = recid(sod_det).

         if sod_rma_type = "O" then do:
            /* FOR RMA SHIPMENT LINES, ENSURE "SHIP BEFORE RECEIPT"
               CONDITIONS (WHICH CAN BE SPECIFIED ON THE SERVICE TYPE)
               WILL NOT BE VIOLATED BY SHIPPING THIS QUANTITY. */
            {gprun.i ""fsshb4r.p""
               "(input sod_nbr,
                 input sod_line,
                 input (lotserial_qty * trans_conv),
                 output msgnbr,
                 output linked-line)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if msgnbr <> 0 then do:
               {pxmsg.i &MSGNUM=msgnbr &ERRORLEVEL=3 &MSGARG1=linked-line}
               lotserial_qty = prev_lotserial_qty.
               undo setlot, retry.
            end.
         end.  /* if sod_rma_type = "O" */

         /* Build sr_wkfl, which holds shipped-from locations */
         undo-all = yes.

         if multi_entry then do:

            /* Prompt for multiple locations */
            sav_global_type = global_type.
            global_type = "shipundo".

            /* IF DOING RMA RECEIPT, WHICH IS TREATED AS A       */
            /* NEGATIVE SO ISSUE, CALL A DIFFERENT MULTI-ENTRY   */
            /* ROUTINE THAT SWITCHES THE SIGN ON THE QUANTITY    */
            /* SO THAT NO INCORRECT ERROR MESSAGES ARE RECEIVED  */
            if sorec = fsrmarec and sod_rma_type = "I" then do:
               {gprun.i ""icsrup3.p"" "(sod_site,
                                        input-output lotnext,
                                        input lotprcpt)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.

            else do:

               assign
                  done_entry = true
                  lineid_list = "".

               for each soddet
                  fields(sod_bo_chg sod_cfg_type sod_confirm
                  sod_cum_qty sod_desc sod_enduser
                  sod_fa_nbr sod_fr_chg sod_fr_class
                  sod_fr_list sod_fr_wt sod_fr_wt_um
                  sod_fsm_type sod_line sod_list_pr
                  sod_loc sod_lot sod_nbr sod_part
                  sod_price sod_pr_list sod_qty_all
                  sod_qty_chg sod_qty_ord sod_qty_pick
                  sod_qty_ship sod_ref sod_rma_type
                  sod_sched sod_sch_data sod_serial
                  sod_site sod_std_cost sod_taxable
                  sod_tax_env sod_tax_in sod_tax_usage
                  sod_type sod_um sod_um_conv sod_upd_isb)
                  where soddet.sod_nbr = sod_det.sod_nbr
                    and soddet.sod_part = sod_det.sod_part
               no-lock:
                  lineid_list = lineid_list +
                                trim(string(soddet.sod_line)) + ",".
               end. /* for each soddet */

               lineid_list = substring(lineid_list,1, ((r-index(lineid_list,",") - 1 )) ).

               do while done_entry:

                  /* ADDED SIXTH INPUT PARAMETER AS NO */
                  {gprun.i ""icsrup.p"" "(input sod_site,
                                          input sod_nbr,
                                          input """",
                                          input-output lotnext,
                                          input lotprcpt,
                                          input no)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  {gprun.i ""icoviss.p"" "(input sod_det.sod_part,
                                           input ship_so,
                                           input lineid_list,
                                           input sod_line,
                                           output overissue_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if overissue_ok then done_entry = false.

               end.

            end.

            if global_type = "shipok" then undo-all = no.
            global_type = sav_global_type.

         end.

         else do:
            ship_line = sod_line.
            /* Validate location */
            {gprun.i ""sosoisu2.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         /* Make sure alias points to SO db in case the of F4 exit */
         {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         assign
            connect_db = so_db
            db_undo = no.
         run check-db-connect
            (input connect_db, input-output db_undo).
         if db_undo then do:
            hide frame b.
            hide frame f.
            hide frame c.
            undo loop0, leave loop0.
         end.
         if undo-all then undo setlot, retry.

         /* WARN USER IF SHIPMENT ADJUSTMENT */
         /* EXCEEDS ORIGINAL SHIPMENT */
         if (sod_qty_ord > 0 and total_lotserial_qty < 0 and
             sod_qty_ship < (total_lotserial_qty * -1))
         or (sod_qty_ord < 0 and total_lotserial_qty > 0 and
            (sod_qty_ship * -1) < total_lotserial_qty)
         then do:
            if sod_fsm_type <> "RMA-RCT" then do:
               /* Reversal qty exceeds original qty shipped */
               {pxmsg.i &MSGNUM=812 &ERRORLEVEL=2 &MSGARG1=sod_qty_ship}
            end.
         end.

         if  sod_sched and sod_cum_qty[3] > 0 and
            sod_cum_qty[1] + total_lotserial_qty >= sod_cum_qty[3]
         then do:
            {pxmsg.i &MSGNUM=8220 &ERRORLEVEL=2}
            /* CUM SHIPPED QTY >= MAX ORDER QTY FOR ORDER SELECTED*/
         end.

         /* WARN USER IF OVERSHIPPING/OVER-RECEIVING (FOR RMA'S)  */
         if (sod_qty_ord < 0 and
            (sod_qty_ship - total_lotserial_qty) < sod_qty_ord)
         then do:
            {pxmsg.i &MSGNUM=7201 &ERRORLEVEL=2}
            /* QTY TO RECEIVE + QTY RECEIVED > QTY EXPECTED */
         end.
         else do:
            if sod_qty_ord * ( sod_qty_ord -
               (sod_qty_ship + total_lotserial_qty) ) < 0 then do:
               l_overship = yes.
               {pxmsg.i &MSGNUM=622 &ERRORLEVEL=2}
               /* Qty shiped > Qty Ordered */
            end.
         end.

         if using_cust_consignment then do:
            /* DETERMINE IF CONIGNMENT LINE */
            {gprunmo.i
               &program = "sosoisd1.p"
               &module = "ACN"
               &param = """(input sod_nbr,
                 input sod_line,
                 input lotserial_qty,
                 input-output table tt_consign_shipment_detail)"""}
         end.  /* if using_cust_consignment */

      end.  /* SETLOT */

      sod_qty_chg = total_lotserial_qty.
      if cancel_bo and not l_overship then
         sod_bo_chg = 0.
      else
      /***********************************************/
      /*  RMA quantites in sod_qty_chg are stored as */
      /*  Positive even though it is negative. Why?  */
      /*  Because I would have to do many + - +      */
      /*  Conversions throughout the code to handle  */
      /*  RMA receipts because receipts are dislayed */
      /*  As positive.  This will have to do for now */
      /***********************************************/
      if sod_fsm_type = "RMA-RCT" then
         sod_bo_chg = sod_qty_ord - sod_qty_ship + sod_qty_chg.
      else
         sod_bo_chg = sod_qty_ord - sod_qty_ship - sod_qty_chg.

      l_overship = no.

      if can-find (first sob_det where sob_nbr    = sod_nbr
         and sob_line   = sod_line)
         and sod_fa_nbr = ""
         and sod_cfg_type <> "1" /* Not "1" Assemble-to-Order */
         and not undo-all
         and sod_type = ""
         and sod_lot    = "" then do:
         repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

            undo-all = no.
            mod_iss = ?.
            FORM /*GUI*/ 
               
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
space(1)
               mod_iss
               space(2)
             SKIP(.4)  /*GUI*/
with frame e row 16 column 21 side-labels 1 down overlay NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-e-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame e = F-e-title.
 RECT-FRAME-LABEL:HIDDEN in frame e = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame e =
  FRAME e:HEIGHT-PIXELS - RECT-FRAME:Y in frame e - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME e = FRAME e:WIDTH-CHARS - .5.  /*GUI*/


            /* SET EXTERNAL LABELS */
            setFrameLabels(frame e:handle).

            repeat with frame e:
/*GUI*/ if global-beam-me-up then undo, leave.

               display yes @ mod_iss.
               set mod_iss.
               leave.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.

            hide frame e.
            if mod_iss <> yes then leave.
            hide frame c.
            hide frame f.
            hide frame b.

            if change_db then do:
               {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

               assign
                  connect_db = ship_db
                  db_undo = no.
               run check-db-connect
                  (input connect_db, input-output db_undo).
               if db_undo then do:
                  hide frame e.
                  undo loop0, leave loop0.
               end.
            end.
            else do:
               sod_recno = recid(sod_det).
            end.

            /* PASSING THE CENTRAL DB sod_qty_chg TO CORRECTLY  */
            /* INITIALIZE BACKFLUSH QTY (back_qty) IN SOISE01.P */

            {gprun.i ""soise01.p"" "(sod_nbr, sod_line, sod_qty_chg)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if change_db then do:
               {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

               assign
                  connect_db = so_db
                  db_undo = no.
               run check-db-connect
                  (input connect_db, input-output db_undo).
               if db_undo then do:
                  hide frame e.
                  undo loop0, leave loop0.
               end.
            end.

            if sorec = fsrmarec then
               view frame f.
            else
               view frame b.

            view frame c.
            pause 0.
            if undo-all = no then leave.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

         if mod_iss <> yes then do:
            for each sr_wkfl exclusive-lock where sr_userid = mfguser
                  and sr_lineid begins string(sod_line) + "ISS":
               delete sr_wkfl.
            end.

            for each lotw_wkfl
               where lotw_mfguser = mfguser
               exclusive-lock:
               delete lotw_wkfl.
            end. /* FOR EACH lotw_wkfl */


         end.
      end. /* IF CAN-FIND */

      /* SWITCHING TO INVENTORY DATABASE */
      if change_db then
      do:
         {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         assign
            connect_db = ship_db
            db_undo    = no.
         run check-db-connect (input connect_db,
            input-output db_undo).
         if db_undo then
         do:
            hide frame b.
            hide frame f.
            hide frame c.
            undo loop0, leave loop0.
         end. /* IF DB_UNDO THEN */
      end. /* IF CHANGE_DB */

      /* SET STANDARD COST FROM INVENTORY DATABASE */
      {gprun.i ""gpsct05.p"" "(input sod_part,
                               input sod_site,
                               input 1,
                               output glxcst,
                               output curcst)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if sod_type <> "M"
      then
         sod_std_cost = glxcst * sod_um_conv.

      /* SWITCHING BACK TO CENTRAL DATABASE */
      if change_db then
      do:
         {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         assign
            connect_db = so_db
            db_undo    = no.
         run check-db-connect (input connect_db,
            input-output db_undo).
         if db_undo then
         do:
            hide frame b.
            hide frame f.
            hide frame c.
            undo loop0, leave loop0.
         end. /* IF DB_UNDO THEN */
      end. /* IF CHANGE_DB */

      if sod_sched then do:
         /* SET CURRENT PRICE */

         /* FOLLOWING SECTION IS ADDED TO REPLACE rcpccal.p WITH gppccal.p  */
         /* TO TAKE CARE OF PRICE LIST TYPES "M" AND "D" IN ADDITION TO "P" */

         for first soc_ctrl
               fields(soc_pl_req soc_returns_isb) no-lock:
         end. /* FOR FIRST SOC_CTRL */

         assign
            l_disc_pct1  = 0
            l_net_price  = ?
            l_rec_no     = ?
            l_list_price = 0.

         /* SCHEDULED ORDERS CAN BE CREATED ONLY IN STOCKING UM */
         /* MULTIPLYING BY sod_um_conv JUST FOR SAFETY          */
         if available pt_mstr then
         do:

            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input base_curr,
                 input so_curr,
                 input exch_rate2,
                 input exch_rate,
                 input (pt_price * sod_um_conv),
                 input false,
                 output l_list_price,
                 output mc-error-number)"}.
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.
         end. /* if available pt_mstr */

         {gprun.i ""gppccal.p""
            "(input  sod_part,
              input sod_qty_chg,
              input sod_um,
              input sod_um_conv,
              input so_curr,
              input sod_pr_list ,
              input eff_date,
              input sod_std_cost,
              input soc_pl_req,
              0.0,
              input-output  l_list_price,
              output l_disc_pct1,
              input-output  l_net_price,
              output l_rec_no)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if l_net_price <> ? then
            sod_price = l_net_price.

         /* SWITCHING TO INVENTORY DATABASE */
         if change_db then
         do:
            {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               connect_db = ship_db
               db_undo    = no.
            run check-db-connect (input connect_db,
               input-output db_undo).
            if db_undo then
            do:
               hide frame b.
               hide frame f.
               hide frame c.
               undo loop0, leave loop0.
            end. /* IF DB_UNDO THEN */
         end. /* IF CHANGE_DB */

         /* UPDATE NET PRICE, LIST PRICE, CUMULATIVE QTY IN */
         /* INVENTORY DATABASE                              */

         {gprun.i ""sosoisu6.p"" "(input sod_nbr,
                                   input sod_line,
                                   input sod_price,
                                   input l_list_price,
                                   input sod_cum_qty[1],
                                   input sod_cum_qty[2],
                                   input sod_cum_qty[3])"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* SWITCHING BACK TO CENTRAL DATABASE */
         if change_db then
         do:
            {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               connect_db = so_db
               db_undo    = no.
            run check-db-connect (input connect_db,
               input-output db_undo).
            if db_undo then
            do:
               hide frame b.
               hide frame f.
               hide frame c.
               undo loop0, leave loop0.
            end. /* IF DB_UNDO THEN */
         end. /* IF CHANGE_DB */

         /* UPDATE SOD_LIST_PRICE FOR SCHEDULE ORDER WHEN   */
         /* SOD_LIST_PRICE IS ZERO OR                       */
         /* LIST PRICE IN ITEM MASTER IS ZERO SO THAT SALES */
         /* AMOUNT SHOULD BE POSTED TO PROPER ACCOUNT       */

         if pt_price    = 0 or
            sod_list_pr = 0 then
            sod_list_pr = sod_price.
      end. /* IF SOD_SCHED */

      /* FREIGHT WEIGHTS */
      if sod_fr_list <> ""
      then do:
         set_wt:
         do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            freight_ok = yes.
            if calc_fr or disp_fr then do:
               detqty = sod_qty_chg.
               /* ADDED SECOND EXCHANGE RATE BELOW */
               {gprun.i ""gpfrlwt.p""
                  "(input so_curr,
                    input so_ex_rate,
                    input so_ex_rate2,
                    input so_fr_min_wt,
                    input so_fr_terms,
                    input so_ship, input eff_date,
                    input sod_fr_list, input sod_part,
                    input detqty, input sod_site,
                    input sod_type, input sod_um,
                    input calc_fr,
                    input disp_fr,
                    input-output sod_fr_wt,
                    input-output sod_fr_wt_um,
                    input-output sod_fr_class,
                    input-output sod_fr_chg,
                    input-output freight_ok)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.
            if not freight_ok then
               undo set_wt, retry.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
   end. /* REPEAT (NOT TRANSACTION) */

   if  sorec = fsrmarec  then
      msgnbr = 7229.
   /* DISPLAY RMA LINES BEING RECEIVED? */
   else
   if so_fsm_type = "SEO" then
      msgnbr = 3353.  /* DISPLAY MATERIAL ORDER LINES BEING SHIPPED? */
   else
   if so_fsm_type  = "KITASS" then
      msgnbr = 817.
   /* DISPLAY KIT ITEMS BEING ASSEMBLED? */
   else
      msgnbr = 618.
   /* DISPLAY SALES ORDER LINES BEING SHIPPED? */

   /* Display Shipment information for user review */
   do on endkey undo loop0,leave loop0:

      l_remove_srwkfl = yes.

      yn = yes.
      /* Display sales order lines being shipped? */

      /*V8+*/

           
      {mfgmsg10.i msgnbr 1 yn}
      if yn = ?
      then
         undo loop0, leave loop0.
        

      l_remove_srwkfl = no.

      if yn = yes then do:

         hide frame b no-pause.
         hide frame f no-pause.
         hide frame c no-pause.

         /* Switch to the shipping db to display the shipment file */
         if ship_db <> global_db then do:
            {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               connect_db = ship_db
               db_undo = no.
            run check-db-connect
               (input connect_db, input-output db_undo).
            if db_undo then do:
               hide frame b.
               hide frame f.
               hide frame c.
               undo loop0, leave loop0.
            end.
         end.

         {gprun.i ""sosoiss1.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         assign
            connect_db = so_db
            db_undo = no.
         run check-db-connect
            (input connect_db, input-output db_undo).
         if db_undo then do:
            hide frame b.
            hide frame f.
            hide frame c.
            undo loop0, leave loop0.
         end.

      end.
   end. /* DO ON ENDKEY */

   do on endkey undo loop0, leave loop0:
      {&SOSOISD-P-TAG5}
      yn = yes.

      l_remove_srwkfl = yes.

      /* Is all info correct? */

      /*V8+*/

           
      {mfgmsg10.i 12 1 yn}
      if yn = ? then
      undo loop0, leave loop0.   
      l_remove_srwkfl = no.

      if yn then do:
         {&SOSOISD-P-TAG6}
         hide frame b.
         hide frame f.
         hide frame c.
         undo-select = false.
         leave loop0.
      end.
   end.
end.  /* LOOP0: REPEAT TRANSACTION */

/* IN GUI THE RETURN KEY IN THE QUESTION ALERT BOX IS NOT RECOGNIZED,*/
/* CONSEQUENTLY THE KEYFUNCTION(LASTKEY)WRONGLY RETURNS F4 OR ESC    */
/* KEY FROM THE PREVIOUS KEYSTROKE CAUSING ERRONEOUS DELETION OF     */
/* SR_WKFL. SO INSTEAD OF RELYING ON LASTKEY WE WILL USE LOGICAL     */
/* VARIABLE TO DETECT IF USER HAS PRESSED END-ERROR OR END-KEY.      */

{&SOSOISD-P-TAG11}

if l_remove_srwkfl then do:
   for each sr_wkfl where sr_userid = mfguser exclusive-lock:
      delete sr_wkfl.
   end.

   for each lotw_wkfl
      where lotw_mfguser = mfguser
      exclusive-lock:
      delete lotw_wkfl.
   end. /* FOR EACH lotw_wkfl */

end.
{&SOSOISD-P-TAG12}

PROCEDURE check-db-connect:
   define input parameter connect_db like dc_name.
   define input-output parameter db_undo like mfc_logical.

   if err-flag = 2 or err-flag = 3 then do:
      /* DB NOT CONNECTED */
      {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=connect_db}
      db_undo = yes.
   end.

END PROCEDURE.

/*  DETERMINE IF LOC TO BE USED IS VALID                                */
PROCEDURE check-reserved-location:

   ret-flag = 2.

   /* bypass checking SSM orders */
   if so_mstr.so_fsm_type = "" then do:
     {gprun.i ""sorlchk.p""
              "(input so_mstr.so_ship,
                input so_mstr.so_bill,
                input so_mstr.so_cust,
                input site,
                input location,
                output ret-flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

END PROCEDURE.
